package com.mawendaxiong.blogprovider.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
public class DatasourcesConfig {
    @Value("${spring.datasource.jdbc-url}")
    private String JDBCURL;
    @Value("${spring.datasource.driver-class-name}")
    private String DRIVERCLASSNAME;
    @Value("${spring.datasource.username}")
    private String USERNAME;
    @Value("${spring.datasource.password}")
    private String PASSWORD;


    @Bean("hikariDataSource")
    public DataSource dataSource() {
        HikariDataSource dataSource = new HikariDataSource();
        dataSource.setJdbcUrl(JDBCURL);
        dataSource.setDriverClassName(DRIVERCLASSNAME);
        dataSource.setUsername(USERNAME);
        dataSource.setPassword(PASSWORD);
        return dataSource;
    }
}
